package com.tianqu.tms.www.transfer.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferSpecialCarCount;
import com.tianqu.tms.www.transfer.actionform.CheckConfirmActionForm;
import com.tianqu.tms.www.transfer.viewhelper.CheckConfirmViewHelper;

public class SpecialCarStatisSearchDisPatchAction extends TmsAction {

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		String actionForward = "";
		CheckConfirmActionForm inForm = (CheckConfirmActionForm)form;
		CheckConfirmViewHelper view = new CheckConfirmViewHelper();
		//往viewhelp中set值
		view.setTsBsFlag(inForm.getTsBsFlag());
		if("1".equals(inForm.getTsBsFlag()))
		{
			//当前
			TransferSpecialCarCount count = new TransferSpecialCarCount();
			count = count.getTransferCountWeekInfo("");
			if(count!=null)
			{
				view.setStartWeekDate(count.getStartWeekDate());
				view.setEndWeekDate(count.getEndWeekDate());
			}else{
				//不显示 区间和查询按钮
				view.setStartWeekDate("");
				view.setEndWeekDate("");
			}
		}
		if("2".equals(inForm.getTsBsFlag()))
		{
			//加载下拉列表
			TransferSpecialCarCount count = new TransferSpecialCarCount();
			List list = count.getTransferCountWeekList();
			view.setWeekList(list);
		}
		if(inForm.getSearchOnButton()!=null && !"".equals(inForm.getSearchOnButton()))
		{
			view.setEndWeekDate(inForm.getEndWeekDate());
			if("2".equals(inForm.getTsBsFlag()))
			{
				//验证
				actionForward = "checkTop";
			}else{
				actionForward = "noCheckTop";
			}
		}else{
			actionForward = "currentPage";
		}
		uc.setAttribute(TmsConstants.VIEWHELP, view);
		return mapping.findForward(actionForward);
	}
}
